#include<bits/stdc++.h>
#define jss301 return
#define ll long long
using namespace std;

struct Sth{
    int r;
    bool att=0;
    bool away=0;
};

int n,sum;Sth a[100000];
int dfs(int k){
    if(n==k) return 0;
    if(!a[k].away) {
        if(a[k].r<a[k+1].r) a[k+1].att=1,a[k].away=1;
        dfs(k+1);
    }
}



bool cmpp(Sth a,Sth b){
    if(a.r<b.r) return 1;
    else return 0;
}

int main()
{
    freopen("duel.in","r",stdin);freopen("duel.out","w",stdout);
    cin>>n;int count=0;
    for(int i=0;i<n;i++) cin>>a[i].r;
    sort(a,a+n,cmpp);
    for(int i=0;i<n-1;i++) count+=a[i+1].r-a[i].r;
    cout<<count;
    fclose(stdin);fclose(stdout);
    jss301 0;
}
